package com.yellowpage.sample.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.sample.data.News;
import com.yellowpage.sample.dao.NewsDao;

public class NewsServiceImpl extends BaseServiceImpl implements NewsService {
	  private NewsDao newsDao;
	
	  public void setNewsDao(NewsDao newsDao) {
		  this.newsDao = newsDao;
	  }
	
	
	  /* White generate Method */ 
	  public News getNews(Long id){
	      return newsDao.get(id);
	  }
	  
    public List<News> getAllNews(){
        return newsDao.getAll();
    }
    
    public List<Map> queryNewsByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.NEWS_ID , a.HTML_TEMPLATE_ID , a.TITLE , a.STATUS,  " +
				"       to_char(a.PUB_TIME, 'yyyy-mm-dd hh:mi:ss') as PUB_TIME," +
				"       (select display_name from CA_USER where user_id = a.last_update_user) as last_update_user, " +
			    "       to_char(a.last_update_time, 'yyyy-mm-dd hh:mi:ss') as last_update_time, " +
			    "       (select display_name from CA_USER where user_id = a.create_user) as create_user," +
			    "       to_char(a.create_time, 'yyyy-mm-dd hh:mi:ss') as create_time " +
				"  FROM WEB_NEWS a WHERE 1=1 ")
			.addCondition(" and HTML_TEMPLATE_ID = :htmlTemplateId ")
		    .addCondition(" and PUB_TIME = to_date(:pubTime ,'yyyy-MM-dd') ")	
			.addCondition(" and TITLE like :title ")
		    ; 	

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveNews(News news){
        newsDao.save(news);
    }
    
	  public void updateNews(News news){
	      newsDao.update(news);
	  }
	  
	  public void delete(List deleteList){
	      newsDao.remove(deleteList);
	  }
	  
	  
	 
	
}	